﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TBlog.Web.Models;
using TBlog.Web.Repository;

namespace TBlog.Web.Service
{
    public class BaseService<T> : IBaseService<T> where T : BaseEntity
    {
        readonly IRepository<T> _repository;
        public BaseService(IRepository<T> repository)
        {
            _repository = repository;
        }
        public virtual int Add(T Entity)
        {
            return _repository.Insert(Entity);
        }

        public virtual int Update(T Entity)
        {
            return _repository.Update(Entity);
        }

        public virtual int Delete(int ID)
        {
            return _repository.Delete(ID);
        }

        public virtual T GetByID(int ID)
        {
            return _repository.GetByID(ID);
        }

        public virtual IQueryable<T> GetAll()
        {
            return _repository.GetAll();
        }


        public IDictionary<string, object> GetJsonMessage(bool success, string date, string message)
        {
            var dictionary = new Dictionary<string, object>();
            dictionary.Add("success", success);
            dictionary.Add("data", date);
            dictionary.Add("message", message);
            return dictionary;
        }
    }
}